import { DataTypes, Model } from "sequelize";
import sequelize from "@db/sequelize";

interface IContact {
    emails: string[];
    phones: string[];
    vk: string;
    telegram: string;
    github: string;
}

interface IContactPerson {
    firstName: string;
    lastName: string;
    jobName: string;
    contacts: IContact;
}

export class Organization extends Model {
    declare id: number;
    declare name: string;
    declare email: string;
    declare password: string;
    declare photo: string;
    declare isVerified: boolean;
    declare isEmailVerified: boolean;
    declare site: string;
    declare description: string;
    declare addresses: string[];
    declare companySize: {
        min: number;
        max: number;
    };
    declare contacts: IContact;
    declare contactPersons: IContactPerson[];
}

Organization.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
            unique: true,
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        email: {
            type: DataTypes.STRING,
            unique: true,
        },
        photo: {
            type: DataTypes.STRING,
        },
        password: {
            type: DataTypes.STRING,
        },
        description: {
            type: DataTypes.STRING,
        },
        site: {
            type: DataTypes.STRING,
        },
        addresses: {
            type: DataTypes.JSONB,
        },
        companySize: {
            type: DataTypes.JSONB,
            defaultValue: {
                min: 0,
                max: 50,
            },
        },
        contacts: {
            type: DataTypes.JSONB,
            defaultValue: {
                phones: [],
                emails: [],
                vk: null,
                telegram: null,
                github: null,
            },
        },
        contactPersons: {
            type: DataTypes.JSONB,
            defaultValue: [],
        },
        isVerified: {
            type: DataTypes.BOOLEAN,
        },
        isEmailVerified: {
            type: DataTypes.BOOLEAN,
        },
    },
    {
        tableName: "organizations",
        sequelize,
    }
);
